'''
 爬虫处理业务
'''
import requests
from bs4 import BeautifulSoup

class pcScrawler():
    def __init__(self):
        self.headers={
            'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95'
        }
    #爬文本
    def getTargetText(self,url,selector):
        codes=requests.get(url,headers=self.headers).text
        bs = BeautifulSoup(codes,'html.parser')
        return str([item.text for item in bs.select(selector=selector)])

    #爬图片
    def getTargetImg(self,imgurl):
        imgc = requests.get(imgurl).content
        with open("2.png",'wb') as f:
            f.write(imgc)

if __name__=='__main__':
    url = "https://3w.huanqiu.com/a/c36dc8/4CMysqpj45T?agt=128"
    s = pcScrawler()
    #<img src="&amp;thumbnail=660x2147483647&amp;quality=80&amp;type=jpg">

    imgurl = "https://rs-channel.huanqiucdn.cn/imageDir/4f9fa84b2366570e91e594083bb3c0c0u1.png"
    print(s.getTargetImg(imgurl))